# Maintainer: Felix Yan <felixonmars@archlinux.org>

_hkgname=libxml
pkgname=haskell-libxml
pkgver=0.1.1
pkgrel=20
pkgdesc="Binding to libxml2"
url="https://hackage.haskell.org/package/libxml"
license=('BSD')
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'libxml2')
makedepends=('ghc')
source=(https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz)
sha512sums=('59a52200e7c7ab17a60a89e4a3aefdf6356e868be6be53696e5708a4d30863ae879834404ccfecb91b6d4b93a7ce0e147a3cc04bc4d5838c2aa990a290af5c5c')

build() {
    cd $_hkgname-$pkgver
    
    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --extra-include-dirs=/usr/include/libxml2 \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm \
            -fsmall_base
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

package() {
    cd $_hkgname-$pkgver
    
    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    install -D -m644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
